package com.purong.purong.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;

/**
 * Created by wenjiezeng on 2017/11/8.
 * 切换无滑动效果
 */
public class SmoothScrollViewPage extends ViewPager {
    private int nowItem;
    private int maxSpace;//间隔页数超过该值无滑动效果
    public SmoothScrollViewPage(Context context) {
        super(context);
    }

    public SmoothScrollViewPage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public void setMaxSpace(int max){
        if (max>=0){
            this.maxSpace=max;
        }else {
            this.maxSpace=0;
        }

    }
    @Override
    public void setCurrentItem(int item) {
        if (Math.abs(nowItem-item)>maxSpace){
            super.setCurrentItem(item,false);
        }else {
            super.setCurrentItem(item);
        }
        nowItem=item;
    }
}
